import { withRouter } from 'react-router-dom';

const Header = (props) => {
	const userId = sessionStorage.getItem('userId');
	const logout = () => {
		sessionStorage.removeItem('userId');
		alert(`退出成功:${userId}`)
		props.history.push({pathname: "/login"});
	};
	const goLogin = () => {
		props.history.push({pathname: "/login"});
	};
	
	return (
		<div className='BaseLayout-header'>
			<div className="BaseLayout-header-l">{userId || '你未登录,请先登录'}</div>
			<div className="BaseLayout-header-r">
				{userId 
					?<span className="logout-btn" onClick={logout}>退出</span>
					:<span className="logout-btn" onClick={goLogin}>前往登录</span>}
				
			</div>
		</div>
	)
};

export default withRouter(Header);
